<template>
  <div id="app">
    <nav-bar />
    <div class="main-content">
      <router-view v-slot="{ Component }">
        <transition name="fade" mode="out-in">
          <component :is="Component" />
        </transition>
      </router-view>
    </div>
  </div>
</template>

<script>
import NavBar from '@/components/NavBar.vue'

export default {
  components: {
    NavBar
  },
  created() {
    // 确保window对象在不同环境中的可用性
    if (typeof window !== 'undefined') {
      // 监听资源加载错误
      window.addEventListener('error', this.handleResourceError, true);
    }
  },
  beforeDestroy() {
    if (typeof window !== 'undefined') {
      window.removeEventListener('error', this.handleResourceError, true);
    }
  },
  methods: {
    // 处理资源加载错误
    handleResourceError(event) {
      // 仅处理资源加载错误，避免处理JS执行错误
      if (event.target && (event.target.tagName === 'SCRIPT' || event.target.tagName === 'LINK' || event.target.tagName === 'IMG')) {
        console.warn('资源加载失败:', event.target.src || event.target.href);
      }
    }
  }
}
</script>
